package com.larry.spark

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

object StreamingWordCount {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("streaming")

    val ssc = new StreamingContext(sparkConf, Seconds(3))

    val lineStream = ssc.socketTextStream("hadoop102", 9999)

    val word = lineStream.flatMap(_.split(" "))

    val wordToOne = word.map((_, 1))

    val wordCount = wordToOne.reduceByKey(_ + _)

    wordCount.print()

    //开启
    ssc.start()

    ssc.awaitTermination()
  }

}
